<?php
namespace yida\modules\listener\controllers;

use yida\controllers\AuthController;
use yida\controllers\ListenerAuthController;
use yida\events\FormEvent;
use Yii;
use yii\web\Controller;

/**
 * 表单事件监听 接口控制器
 * Class BaseController
 * @package yida\modules\listener\controllers
 */
class FormController extends ListenerAuthController
{

    /**
     * 表单创建成功事件
     * @return mixed
     */
    public function actionCreate()
    {
        $request = [
            'get'=>Yii::$app->request->get(),
            'post'=>Yii::$app->request->post(),
            'header'=>Yii::$app->request->getHeaders(),
        ];

        $db = Yii::$app->mongodb_yida_backup;
        $collection = $db->getCollection("event_test");
        $collection->insert($request);

        $event = new FormEvent();
        $event->formInstanceId = 0;
        return [
            'code'=>0,
            'data'=>$request,
        ];
    }

    /**
     * 表单更新成功事件
     * @return mixed
     */
    public function actionUpdate()
    {
        return [
            'code'=>0,
            'data'=>'',
        ];
    }

    /**
     * 表单删除成功事件
     * @return mixed
     */
    public function actionDelete()
    {
        return [
            'code'=>0,
            'data'=>'',
        ];
    }

    /**
     * 表单评论成功事件
     * @return mixed
     */
    public function actionCommit()
    {
        return [
            'code'=>0,
            'data'=>'',
        ];
    }
}